package com.liuceng.peatio.service

import com.liuceng.BaseSpec
import com.liuceng.peatio.mapper.MemberInputMobileDatasMapper
import com.liuceng.peatio.mapper.MemberInputPcDatasMapper
import com.liuceng.peatio.model.MemberInputMobileDatas
import com.liuceng.peatio.model.MemberInputPcDatas

import static spock.util.matcher.HamcrestMatchers.closeTo
import static spock.util.matcher.HamcrestSupport.that

/**
 * Created by liyuhang on 2016-13-11.
 */
class MemberInputServiceSpec extends BaseSpec {

    def "test .getLastNotDealedMobileInputDatasCost"() {
        given:
        MemberInputMobileDatasMapper mapper = Mock() {
            selectByLastTime(_) >> [new MemberInputMobileDatas(cost: new BigDecimal(90.23), dealed: false), new MemberInputMobileDatas(cost: new BigDecimal(190.23), dealed: false), new MemberInputMobileDatas(cost: new BigDecimal(1000), dealed: true)]
        }
        MemberInputService service = new MemberInputService(memberInputMobileDatasMapper: mapper)

        when:
        BigDecimal result = service.getLastNotDealedMobileInputDatasCost(1)

        then:
        that result, closeTo(280, 0.46)
    }

    def "test .getLastNotDealedMobileInputDatasCost1"() {
        given:
        MemberInputMobileDatasMapper mapper = Mock() {
            selectByLastTime(_) >> [new MemberInputMobileDatas(cost: new BigDecimal(90.23), dealed: true), new MemberInputMobileDatas(cost: new BigDecimal(190.23), dealed: true), new MemberInputMobileDatas(cost: new BigDecimal(1000), dealed: true)]
        }
        MemberInputService service = new MemberInputService(memberInputMobileDatasMapper: mapper)

        when:
        BigDecimal result = service.getLastNotDealedMobileInputDatasCost(1)

        then:
        that result, closeTo(0, 0)
    }

    def "test .getLastNotDealedPcInputDatasCost"() {
        given:
        MemberInputPcDatasMapper mapper = Mock() {
            selectByLastTime(_) >> [new MemberInputPcDatas(cost: new BigDecimal(90.23), dealed: false), new MemberInputPcDatas(cost: new BigDecimal(190.23), dealed: false), new MemberInputPcDatas(cost: new BigDecimal(1000), dealed: true)]
        }
        MemberInputService service = new MemberInputService(memberInputPcDatasMapper: mapper)

        when:
        BigDecimal result = service.getLastNotDealedPcInputDatasCost(1)

        then:
        that result, closeTo(280, 0.46)
    }

    def "test .getLastNotDealedPcInputDatasCost1"() {
        given:
        MemberInputPcDatasMapper mapper = Mock() {
            selectByLastTime(_) >> [new MemberInputPcDatas(cost: new BigDecimal(90.23), dealed: true), new MemberInputPcDatas(cost: new BigDecimal(190.23), dealed: true), new MemberInputPcDatas(cost: new BigDecimal(1000), dealed: true)]
        }
        MemberInputService service = new MemberInputService(memberInputPcDatasMapper: mapper)

        when:
        BigDecimal result = service.getLastNotDealedPcInputDatasCost(1)

        then:
        that result, closeTo(0, 0)
    }
}